<%@ page import="org.codehaus.groovy.grails.plugins.ofchart.demo.DemoCharts" contentType="text/html;charset=UTF-8" %>

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="layout" content="main" />
    <title>Team uploaded PSP Data</title>
  </head>
  <g:javascript library="prototype"/>  
  <ofchart:resources/>
  <body>
    <div class="nav">
      <span class="menuButton"><a class="home" href="${createLink(uri: '/pspData')}">PSP Data</a></span>
    </div>
    <div>
      <br />
      <h1>Team uploaded PSP data</h1>
      <g:form method="post" class="inline">
        Select a Project:
        <g:select name="project.id"
                  from="${session.projectList}" optionKey="id"
                  value="${session.project?.id}"
                  optionValue="name" />
        <span class="button"><g:actionSubmit class="save" action="list" value="Go" /></span>
      </g:form>

      <g:if test="${session.project}">

        <div class="list">
          <table>
            <thead>
              <tr>
            <g:sortableColumn property="name" title="${message(code: 'task.name.label', default: 'Name')}" />
            <g:sortableColumn property="description" title="${message(code: 'task.description.label', default: 'Description')}" />
            <g:sortableColumn property="startDate" title="${message(code: 'task.startDate.label', default: 'Start Date')}" />
            <g:sortableColumn property="endDate" title="${message(code: 'task.endDate.label', default: 'End Date')}" />
            <g:each in="${session.projectTeams}" status="j" var="projectTeam">
              <th>${projectTeam.user.username}</th>
            </g:each>
            </tr>
            </thead>
            <tbody>
            <g:each in="${session.project.tasks}" status="i" var="taskInstance">
              <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
              <td>${fieldValue(bean: taskInstance, field: "name")}</td>
              <td>${fieldValue(bean: taskInstance, field: "description")}</td>
              <td><g:formatDate  format="dd-MM-yyyy HH:mm" date="${taskInstance.startDate}" /></td>
              <td><g:formatDate  format="dd-MM-yyyy HH:mm" date="${taskInstance.endDate}" /></td>
              <g:each in="${session.projectTeams}" status="j" var="projectTeam">
                <td class="center">
                <g:if test="${PspData.hasAnyData(projectTeam.user, taskInstance)}">
                  <g:link controller="pspData" action="show" params="[userId: projectTeam.user.id, taskId: taskInstance.id]">
                    <img src="<g:createLinkTo dir='images/icon' file='show.png'/>" alt="show"/>
                  </g:link>
                </g:if>
                <g:else>-
                </g:else>
                </td>
              </g:each>
              </tr>
            </g:each>
            </tbody>
          </table>
        </div>
        <br />
        <g:link action="burn_down_table" params="[projectId: session.project.id]">Burn Down Table</g:link> | 
         <g:link action="burn_down_chart_page" params="[projectId: session.project.id,chartType: 'team']">Burn Down Chart</g:link>
      </g:if>
    </div>
  </body>
</html>
